package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.OfficialStudent;
import cn.wolfcode.crm.domain.StudentLossItem;
import cn.wolfcode.crm.query.OfficialStudentQueryObj;
import cn.wolfcode.crm.service.IOfficialStudentService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("officialStudent")
public class OfficialStudentController {

    @Autowired
    private IOfficialStudentService officialStudentService;

    @RequestMapping("")
    @RequiresPermissions(value = {"正式学员首页","officialStudent:index"} ,logical = Logical.OR)
    public String index(){

        return "officialStudent/list";
    }

    @RequestMapping("list")
    @RequiresPermissions(value = {"正式学员列表","officialStudent:list"} ,logical = Logical.OR)
    @ResponseBody
    public PageResult list(OfficialStudentQueryObj qo){
        PageResult result = officialStudentService.query(qo);
        return result;
    }
    @RequestMapping("listData")
    @ResponseBody
    public Object listData(){
        return officialStudentService.list();
    }

    @RequestMapping("save")
    @RequiresPermissions(value = {"正式学员保存","officialStudent:save"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult save(OfficialStudent entity){
        JSONResult result = new JSONResult();
        try{
            officialStudentService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("saveChangeClass")
    @RequiresPermissions(value = {"学员班级转换保存","officialStudent:saveChangeClass"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult saveChangeClass(OfficialStudent entity){
        JSONResult result = new JSONResult();
        try{
            officialStudentService.saveChangeClass(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("quitClass")
    @RequiresPermissions(value = {"学员休学","officialStudent:quitClass"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult quitClass(Long id){
        JSONResult result = new JSONResult();
        try{
            officialStudentService.quitClass(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("recoverClass")
    @RequiresPermissions(value = {"学员复学","officialStudent:recoverClass"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult recoverClass(Long id){
        JSONResult result = new JSONResult();
        try{
            officialStudentService.recoverClass(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("saveLossStu")
    @RequiresPermissions(value = {"学员流失","officialStudent:saveLossStu"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult saveLossStu(StudentLossItem entity){
        JSONResult result = new JSONResult();
        try{
            officialStudentService.saveLossStu(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @RequiresPermissions(value = {"正式学员更新","officialStudent:update"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult update(OfficialStudent entity){
        JSONResult result = new JSONResult();
        try{
            officialStudentService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }


    @RequestMapping("delete")
    @RequiresPermissions(value = {"正式学员删除","officialStudent:delete"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            officialStudentService.delete(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }
}
